<template>
  <div class="header">
    <div class="left">
      <span class="icon iconfont icon-caidan"></span>
      <span>数智运维</span>
    </div>
    <div class="center">
      <div class="menu" v-for="menu in menuList" :key="menu.id">
        <div class="text">{{ menu.text }}</div>
        <div><span class="icon iconfont icon-xiangxia"></span></div>
        <div class="sub">
          <ul>
            <li @click="menuClick(child)" v-for="child in menu.child" :key="child.id">
              {{ child.text }}
            </li>
          </ul>
        </div>
      </div>
    </div>
    <div class="right">
      <div class="item head">
        <img :src="head" />
      </div>
      <div class="item">admin</div>
      <div class="item"><span class="icon iconfont icon-shezhi"></span></div>
      <div class="item"><span class="icon iconfont icon-ai240"></span></div>
    </div>
  </div>
</template>

<script setup lang="ts" name="header">
import { reactive } from 'vue'
import { type MenuInter, type MenuList, getMenuList } from '@/types/menu'
import { useRouter } from 'vue-router'
import head from '@/assets/img/head.png'

const menuList: MenuList = reactive(getMenuList())

const router = useRouter()
function menuClick(item: MenuInter) {
  router.push(item.router || '')
}
</script>

<style lang="scss" scoped>
.header {
  width: 100%;
  height: 60px;
  min-width: 1200px;
  color: white;
  background-color: #5f6b86;
  display: flex;
  justify-content: space-between;
  align-items: center;
  position: absolute;
  z-index: 10;

  .left {
    padding: 0px 20px;
    font-size: 24px;
    font-weight: 800;
    margin-right: 200px;
    display: flex;
    align-items: center;

    .icon {
      font-size: 32px;
      font-weight: bold;
      margin-right: 20px;
    }
  }

  .center {
    flex: 1;
    display: flex;
    font-size: 18px;
    font-weight: 600;

    .menu {
      padding: 10px 20px;
      margin: 0px 0px;
      display: flex;
      cursor: pointer;
      position: relative;

      .text {
        margin-right: 5px;
      }

      .sub {
        position: absolute;
        left: 0;
        top: 25px;
        background-color: #5f6b86;
        display: none;
        z-index: 10000;
        font-size: 15px;
        font-weight: 600;
        padding: 10px 0px;
      }
    }

    .menu:hover {
      background-color: #5f6b86;

      .sub {
        display: block;
        background-color: #5f6b86;
        margin-top: 20px;
        width: 100%;

        ul {
          width: 100%;
          padding: 0px;

          li {
            list-style: none;
            color: white;
            padding: 10px 10px;
          }

          li:hover {
            background-color: #409eff;
          }
        }
      }
    }
  }

  .right {
    display: flex;
    align-items: center;

    .item {
      margin-right: 20px;

      .icon-shezhi {
        font-size: 18px;
      }

      .icon-ai240 {
        font-size: 26px;
      }
    }

    .head img {
      width: 40px;
      height: 40px;
      border-radius: 20px;
    }
  }
}
</style>
